<?php

	class WS_StudentInformationCon {
		
		private $DBADMIN;
		private $HASHID;
		
		public function __construct() {

			$this->DBMOD 	= new WS_StudentInformationMod();
			$this->HASHID 	= sha1(time());

		}
		
		public function gradeConvertion($strGrade) {
			return $this->DBMOD->gradeConvertion($strGrade);
		}
		
		public function getScheduleDefaultTime($arrDaysSchedules, $strYearActive = '') {
			
			$result = $this->DBMOD->getScheduleDefaultTime($arrDaysSchedules, $strYearActive);
			
			if (!empty($result) ) {
				foreach($result as $resultField => $resultValue) {
					$return[$resultValue['sched_key']][] = $resultValue;
				}
			}
			
			return $return;
			
		}
		
		# List of Accounts
		public function listCountStudentInformation($strSearch = '') {
			
			$return = $this->listStudentInformation($strSearch, '');
			
			return count($return);
			
		}
		
		# List of Accounts
		public function listStudentInformation($strSearch = 'Search here...', $pageLimit = '') {
			
			if ( $strSearch == 'Search here...' ) {
				$strSearch = '';
			}
			
			return $this->DBMOD->listStudentInformation($strSearch, $pageLimit);
			
		}
		
		# List of Accounts
		public function listCountStudentInformationValidate($strSearch = '', $activeYear) {
			
			$return = $this->listStudentInformationValidate($strSearch, $activeYear, '');
			
			return count($return);
			
		}
		
		# List of Accounts
		public function listStudentInformationValidate($strSearch = 'Search here...', $activeYear, $pageLimit = '') {
			
			if ( $strSearch == 'Search here...' ) {
				$strSearch = '';
			}
			
			return $this->DBMOD->listStudentInformationValidate($strSearch, $activeYear, $pageLimit);
			
		}
		
		public function arraySearchStudentInformationCount($strYearID = '', $strSearch = '') {
			
			$return = $this->DBMOD->arraySearchStudentInformation($strYearID, $strSearch, '');
			
			return count($return);
			
		}
		
		public function arraySearchStudentInformation($strYearID = '', $strSearch = '', $pageLimit = '') {
			
			return $this->DBMOD->arraySearchStudentInformation($strYearID, $strSearch, $pageLimit);
			
		}
		
		public function insertStudentInformation($strArray, $isActive = false) {
			
			return $this->DBMOD->insertStudentInformation($strArray, $isActive);
			
		}
		
		public function getLastStudentID() {
		
			return $this->DBMOD->getLastStudentID();
		
		}
		
		public function getStudentInformation($strID) {
		
			return $this->DBMOD->getStudentInformation($strID);
		
		}
		
		private function gradeEquivalent($strGrades, $strConvertion) {
			
			if (!empty($strGrades)) {
				if ( $strGrades == 'INC' )
					$equivalence = '<span class="font-red">INCOMPLETE</span>';
				elseif ( $strGrades == 'DRP' )
					$equivalence = '<span class="font-red">DROP</span>'; 
				else
					$equivalence = $strConvertion; 
			}
			else $equivalence = 'none';
			
			return $equivalence;
			
		}
		
		public function studentTransferyGrades($strArray, $strGrades = '', $strActiveID = '') {
		
			if (empty($strActiveID)) {
				$returnID 	= $this->DBMOD->insertStudentTransferyGrades($strArray, $strActiveID);
			}
			else {
				$returnID 	= $this->DBMOD->updateStudentTransferyGrades($strArray, $strActiveID);
			}
			
			$convertion = $this->DBMOD->gradeConvertion($strGrades);
			
			return array('stud_subj_id'		=> $returnID,
						 'grade_convertion'	=> $this->gradeEquivalent($strGrades, $convertion['equivalence']),
						 'description'		=> $convertion['description']);
		
		}
		
		public function studentGrades($strGrades = '', $strActiveID = '') {
		
			$returnID 	= $this->DBMOD->updateStudentGrades($strGrades, $strActiveID);
			
			$convertion = $this->DBMOD->gradeConvertion($strGrades);
			
			return array('stud_subj_id'		=> $returnID,
						 'grade_convertion'	=> $this->gradeEquivalent($strGrades, $convertion['equivalence']),
						 'description'		=> $convertion['description']);
		
		}
		
		public function getStudentSubjectGrades($strStudentID, $strSubjectID, $strCourseID, $strSemesterID) {
		
			$result = $this->DBMOD->getStudentSubjectGrades($strStudentID, $strSubjectID, $strCourseID, $strSemesterID);

			if (!empty($result)) {
				
				$grade = $result['grade'];
				
				if ( !empty($grade) ) {
					
					$convertion = $this->DBMOD->gradeConvertion($grade);
					
					$equivalence = $this->gradeEquivalent($grade, $convertion['equivalence']); 

					return array('stud_subj_linker_idPK'	=> $result['stud_subj_linker_idPK'],
								 'subj_idFK'				=> $result['subj_idFK'],
								 'grade'					=> $grade,
								 'grade_remarks'			=> $result['grade_remarks'],
								 'equivalence'				=> $equivalence,
								 'letter_equivalence'		=> $convertion['letter_equivalence'],
								 'description'				=> $convertion['description']);
				}
			}
		
		}
		
		public function getStudentSubjectListSemester($strStudentID, $strCourseID, $strActiveSemester) {
			
			return $this->DBMOD->getStudentSubjectListSemester($strStudentID, $strCourseID, $strActiveSemester);
			
		}
		
		public function getStudentSectionSubjectGenerateSchedules($strStudID, $strCourseID, $strSemLinkerID, $strSectionID, $strSchedTimeID) {
			
			return $this->DBMOD->getStudentSectionSubjectGenerateSchedules($strStudID, $strCourseID, $strSemLinkerID, $strSectionID, $strSchedTimeID);
			
			
		}
		
		public function getStudentSubjectGradesList($strStudentID, $strCourseID, $strActiveSemester = '') {
			
			$result = $this->DBMOD->getStudentSubjectGradesList($strStudentID, $strCourseID, $strActiveSemester);
			
			if(!empty($result)) {
				foreach($result as $resultField => $resultValue) {
					
					$grade = $resultValue['grade'];
					
					$convertion = $this->DBMOD->gradeConvertion($grade);
					
					$equivalence = $this->gradeEquivalent($strGrades, $convertion['equivalence']); 
					
					$res[$resultValue['sem_idFK']][] = array('stud_subj_linker_idPK' => $resultValue['stud_subj_linker_idPK'],
															 'sem_idFK' 			 => $resultValue['sem_idFK'],
															 'subj_idPK' 			 => $resultValue['subj_idPK'],
															 'subj_desc' 			 => $resultValue['subj_desc'],
															 'subj_code' 			 => $resultValue['subj_code'],
															 'grade' 				 => $grade,
															 'equivalence' 			 => $equivalence,
															 'grade_remarks' 		 => $resultValue['grade_remarks']);
				}
			}
			else {
				$res = false;
			}
			
			return $res;
			
		}
		
		public function getStudentSubjectList($strStudentID, $strCourseID, $strActiveSemester = '') {
			
			return $this->DBMOD->getStudentSubjectGradesList($strStudentID, $strCourseID, $strActiveSemester);
			
		}
		
		public function getStudentSubjectTakenList($strStudentID, $strCourseID, $strActiveSemester) {
			
			return $this->DBMOD->getStudentSubjectTakenList($strStudentID, $strCourseID, $strActiveSemester);
			
		}
		
		public function getStudentSubjectTakenListReg($strStudentID, $strCourseID, $strActiveSemester) {
			
			return $this->DBMOD->getStudentSubjectTakenListReg($strStudentID, $strCourseID, $strActiveSemester);
			
		}
		
		public function updateStudDropSubjIrreg($strStatus, $strTableRequest, $strTableID) {
			
			$this->DBMOD->updateStudDropSubjIrreg($strStatus, $strTableRequest, $strTableID);
			
		}
		
		public function deleteSubjEnrolled($strStudSubjLinkerID) {
			
			$result 			= $this->DBMOD->deleteSubjEnrolled($strStudSubjLinkerID);
			$subjEnrolled 		= $this->DBMOD->getSubjEnrolled($result['stud_idFK'], $result['course_idFK'], $result['year_idFK'], $result['stud_sem_active']);
			
			if ( $subjEnrolled['tssl'] == 0 ) {
				
				$subjEnrolledVal = $this->DBMOD->getSubjEnrolledValue($result['stud_idFK'], $result['course_idFK'], $result['year_idFK'], $result['stud_sem_active']);
				$this->DBMOD->deleteStudSecEnrolled($subjEnrolledVal['stud_sem_idPK'], $result['course_idFK'], $result['stud_sem_active']);
				
				$this->DBMOD->deleteStudSemEnrolled($result['stud_idFK'], $result['course_idFK'], $result['year_idFK'], $result['stud_sem_active']);
				
				return 0;
			}
			
			return 1;
			
		}
		
		public function deleteSubjEnrolledGrades($strStudSubjLinkerID) {
			
			$this->DBMOD->deleteSubjEnrolledGrades($strStudSubjLinkerID);
			
		}
		
		public function getStudentReqesutSubjectDelete($strStudID, $strStudentSemActiveID) {

			return $this->DBMOD->getStudentReqesutSubjectDelete($strStudID, $strStudentSemActiveID);
			
		}
		
		public function getStudentSubjectTakenListSeperateBySem($strStudentID, $strCourseID, $strActiveSemester) {
			
			$result = $this->DBMOD->getStudentSubjectTakenList($strStudentID, $strCourseID, $strActiveSemester);
			
			if(!empty($result)) {
				foreach($result as $resultField => $resultValue) {
					$res[$resultValue['sem_idFK']][] = $resultValue;
				}
			}
			
			return $res;
			
		}
		
		public function getStudSemValidation($studID, $courseID, $semLinkerID, $yearID) {
			
			$result = $this->DBMOD->getStudSemValidation($studID, $courseID, $semLinkerID, $yearID);
			return $result['count'];
			
		}
		
		public function ActivateStudentSemester($strActiveSemesterID) {
			
			$this->DBMOD->ActivateStudentSemester($strActiveSemesterID);
			
		}
		
		public function getStudentSubjectTakenListSeperateBySemValidate($strStudentID, $strCourseID, $strActiveSemester) {
			
			$result = $this->DBMOD->getStudentSubjectTakenListValidate($strStudentID, $strCourseID, $strActiveSemester);
			
			if(!empty($result)) {
				foreach($result as $resultField => $resultValue) {
					$res[$resultValue['sem_idFK']][] = $resultValue;
				}
			}
			
			return $res;
			
		}
		
		public function getScheduleTimePerSubj($strSubjID) {
			
			return  $this->DBMOD->getScheduleTimePerSubj($strSubjID);
			
			
		}
		
		public function getStudentSubjectGradesListWithOutSemIdentities($strStudentID, $strCourseID, $strActiveSemester = '') {
			
			return $this->DBMOD->getStudentSubjectGradesList($strStudentID, $strCourseID, $strActiveSemester);
		}
		
		public function getStudSubjUntakenPerSemester($strSubjTaken, $strSemTaken, $semLinkerID = '') {
			
			return $this->DBMOD->getStudSubjUntakenPerSemester($strSubjTaken, $strSemTaken, $semLinkerID);
			
		}
		
		public function manualSubjRequisite() {
			
			 $this->DBMOD->manualSubjRequisite();
			 
		}
		
		public function getSemesterEnrollmentActive($studID) {
			
			return $this->DBMOD->getPassFailedEnrollment($studID);
			
		}
		
		public function getIrregularSemesterList($studID, $semSubjLinkerID) {
			
			$return = $this->DBMOD->getIrregularSemesterList($studID, $semSubjLinkerID);
			
			if (!empty($return)) {
				foreach($return as $value) {
					$irregularSemesterListSection = $this->DBMOD->getIrregularSemesterListSection($value['sem_idFK']);
					$res[] = $irregularSemesterListSection['section_idPK'];
				}
			}
			
			return $res;
			
		}
		
		public function getSemesterSubjectList($strSemLinkerID) {
			
			$return = $this->DBMOD->getSemesterSubjectList($strSemLinkerID);
			
			return $return['count'];
			
		}
		
		public function activateStudent($studID) {
			
			return $this->DBMOD->activateStudent($studID);
			
		}
		
		public function getPassFailedEnrollmentSubject($studID, $semSubjLinkerID) {
			
			return $this->DBMOD->getPassFailedEnrollmentSubject($studID, $semSubjLinkerID);
			
		}
		
		public function getPassFailedEnrollment($studID) {
			
			$result = $this->DBMOD->getPassFailedEnrollment($studID);
			
			$resFPES = $this->DBMOD->getPassFailedEnrollmentSubject($studID, $result['sem_linker_idFK']);
			
			if (!empty($resFPES)) {
				$countGrade  = 0;
				$passedGrade = 0;
				foreach($resFPES as $resFPESValue) {
					if ( empty($resFPESValue['grades']) ) {
						$countGrade++;
					}
					else {
						$passedGrade++;
					}
				}
			}
			else {
				$payment = TRUE;
			}
			
			return array('payment' => $payment, 'empty_grade' => $countGrade, 'pass_grade' => $passedGrade);
			
		}
		
		public function getInsertStudSubjEnrollID($studID, $courseID, $activeYear, $strSubjEnroll, $activeSubjTaken, $strStudSemLinkerID = '') {
			
			$result 			= $this->DBMOD->getStudSubjEnrollID($strSubjEnroll, $courseID);
			$studSubjEnrollID 	= $this->DBMOD->getStudSubjEnrollIDSemester($strSubjEnroll, $courseID);
			
			$isRegularStudent 	= (count($studSubjEnrollID) > 1) ? 'N' : 'Y';
			if(!empty($result)) {
				$totalUnits = 0;
				foreach($result as $resultValue) {
					$strArray = array('stud_id'		=> $studID,
									  'subj_id'		=> $resultValue['subj_idPK'],
									  'course_id'	=> $courseID,
									  'sem_id'		=> $resultValue['sem_linker_idFK'],
									  'year_id'		=> $activeYear,
									  'grades'		=> '',
									 );
					$this->DBMOD->insertStudentTransferyGrades($strArray, $activeSubjTaken);
				}
				$this->DBMOD->insertStudentSemesterActive($studID, $courseID, $activeSubjTaken, $activeYear, $isRegularStudent);
			}
		}
		
		public function getInsertStudSubjEnrollIDViaID($studID, $courseID, $activeYear, $strSubjEnroll, $activeSubjTaken, $strStudSemLinkerID = '') {
			
			$result 			= $this->DBMOD->getStudSubjEnrollIDViaID($strSubjEnroll, $courseID);
			$studSubjEnrollID 	= $this->DBMOD->getStudSubjEnrollIDSemesterViaID($strSubjEnroll, $courseID);
			
			$isRegularStudent 	= (count($studSubjEnrollID) > 1) ? 'N' : 'Y';
			if(!empty($result)) {
				$totalUnits = 0;
				foreach($result as $resultValue) {
					$strArray = array('stud_id'		=> $studID,
									  'subj_id'		=> $resultValue['subj_idPK'],
									  'course_id'	=> $courseID,
									  'sem_id'		=> $resultValue['sem_linker_idFK'],
									  'year_id'		=> $activeYear,
									  'grades'		=> '',
									 );
					$this->DBMOD->insertStudentTransferyGrades($strArray, $activeSubjTaken);
				}
				$this->DBMOD->insertStudentSemesterActive($studID, $courseID, $activeSubjTaken, $activeYear, $isRegularStudent);
			}
		}
		
		public function insertStudentSemesterActive($studID, $courseID, $activeSubjTaken, $activeYear, $isRegularStudent = 'Y') {
			
			$this->DBMOD->insertStudentSemesterActive($studID, $courseID, $activeSubjTaken, $activeYear, $isRegularStudent);
		}
		
		public function insertStudentTransferyGrades($strArray, $activeSubjTaken) {
			
			return $this->DBMOD->insertStudentTransferyGrades($strArray, $activeSubjTaken);
		}
		
		public function getSemAlreadyTeken($studID, $courseID) {
			
			return $this->DBMOD->getSemAlreadyTeken($studID, $courseID);
		}
		
		public function getStudentEnrolled($semLinkerID, $strCourse, $strActiveYear = '') {
			
			return $this->DBMOD->getStudentEnrolled($semLinkerID, $strCourse, $strActiveYear);
			
		}
		
		public function updateStudentSection($strSectionID, $strStudSecSemID, $strCourseID, $strSemLinkerID) {
			
			$this->DBMOD->updateStudentSection($strSectionID, $strStudSecSemID, $strCourseID, $strSemLinkerID);
			
		}
		
		public function updateStudentChangeSection($strRequestSectionID, $strRequestStatus, $strStudNo) {
			
			$this->DBMOD->updateStudentChangeSection($strRequestSectionID, $strRequestStatus);
			
			$this->DBMOD->deleteStudentRequestPassword($strStudNo);
			
		}
		
		public function getStudentEnrolledSections($semLinkerID, $strCourse, $strCourseCode, $semLinkerID, $studCountSection = 3) {
			/*
				$secsList	= $this->getDefaultSections($strCourse);
			$studs 		= $this->DBMOD->getStudentEnrolled($semLinkerID, $strCourse);
			
			if (!empty($secsList)) {
				$studSectionSemCount = 0;
				foreach($secsList as $secsField => $secsVal) {
					$totalStudSecEnrolled = $this->DBMOD->getStudentSectionSemester($strCourse, $secsVal['section_idPK'], $semLinkerID);
					if ( $totalStudSecEnrolled['count_stud_sec'] < $secsVal['no_stud'] ) {
						$secs[] = array('section_idPK'	=> $secsVal['section_idPK'],
										'section_desc'	=> $secsVal['section_desc'],
										'course_idFK'	=> $secsVal['course_idFK'],
										'no_stud'		=> ($secsVal['no_stud'] - $totalStudSecEnrolled['count_stud_sec']));
						$studSectionSemCount++;
					}
				}
			}
			
			$countSections = (count($secs) - 1);
			if (!empty($studs)) {
				$studCounter = 1;
				$secCounter  = 0;
				$return		 = array();
				foreach($studs as $studsVal) {
					$studEnrolledSection = $this->DBMOD->getStudentSectionEnrolled($studsVal['stud_sem_idPK']);
					if ( $studEnrolledSection['stud_sec'] <= 0 ) {
						
						$studNoSection 	= $secs[$secCounter]['no_stud'];
						
						if ($studCounter <= $studNoSection) {
							$sectionID 	  = $secs[$secCounter]['section_idPK'];
							$this->DBMOD->insertStudentSectionSemester($studsVal['stud_sem_idPK'], $strCourse, $sectionID, $semLinkerID);
							$return[$sectionID][] = $studsVal;
							$studCounter++;
						}
						else {
							$studCounter = 1;
							$secCounter++;
							if (empty($secs[$secCounter]['section_idPK'])) {
								$sectionID 	= $this->insertDefaultSections($strCourseCode . '-' . $strCourse . $secCounter, $strCourse, $studCountSection);
							}
							else {
								$sectionID 	= $secs[$secCounter]['section_idPK'];
							}
							$this->DBMOD->insertStudentSectionSemester($studsVal['stud_sem_idPK'], $strCourse, $sectionID, $semLinkerID);
							$return[$sectionID][] = $studsVal;
							$studCounter++;
						}
						
					}
				}
			}
			
			return $return;
			*/
		}
		
		public function insertStudentSectionSemester($strStudentSem, $strCourse, $strSectionID, $semLinkerID) {
			
			return $this->DBMOD->insertStudentSectionSemester($strStudentSem, $strCourse, $strSectionID, $semLinkerID);
			
		}
		
		public function getStudentSectionSemesterAssigned($strCourse, $strSemLinker, $strYearID) {
			
			$return = $this->DBMOD->getStudentSectionSemesterAssigned($strCourse, $strSemLinker, $strYearID);
			
			return count($return);
			
		}
		public function getStudentSectionSemester($strCourse, $strSection, $strSemLinker, $strYearID) {
			
			$return = $this->DBMOD->getStudentSectionSemester($strCourse, $strSection, $strSemLinker, $strYearID);
			
			return count($return);
			
		}
		
		public function getStudentSectionEnrolled($strStudSemID) {
			
			return $this->DBMOD->getStudentSectionEnrolled($strStudSemID);
			
		}
		
		public function getStudSectionDesc($strStudID, $sstrCourseID, $strSemLinkerID) {
			
			return $this->DBMOD->getStudSectionDesc($strStudID, $sstrCourseID, $strSemLinkerID);
			
		}
		
		
		public function getListingStudentSectionSemester($strCourse, $strSection, $strSemLinker) {
			
			return $this->DBMOD->getListingStudentSectionSemester($strCourse, $strSection, $strSemLinker);
			
		}
		
		public function insertDefaultSections($strSectionDesc, $strCourse, $strSemester, $strNoStudent) {
			
			return $this->DBMOD->insertDefaultSections($strSectionDesc, $strCourse, $strSemester, $strNoStudent);
			
		}
		
		public function updateDefaultSections($strSectionDesc, $strCourse, $strSemester, $strNoStudent, $strSectionID) {
			
			return $this->DBMOD->updateDefaultSections($strSectionDesc, $strCourse, $strSemester, $strNoStudent, $strSectionID);
			
		}
		
		public function emptyStudSection($strSectionID) {
			
			return $this->DBMOD->emptyStudSection($strSectionID);
			
		}
		
		public function updateDeptSection($strSectionID) {
			
			return $this->DBMOD->updateDeptSection($strSectionID);
			
		}
		
		public function getDefaultSections($strCourse, $strSectionID = '', $strSemesterID = '') {
			
			return $this->DBMOD->getDefaultSections($strCourse, $strSectionID, $strSemesterID);
			
		}
		
		public function getListProfStudentPerSubjCount($strSemLinkerID, $strUserID, $strProfSujID, $strSectionID = '', $strSearch = 'Search here...', $strLimit = '', $strYear = '') {
			
			if ( $strSearch == 'Search here...' ) $strSearch = '';
			
			$result = $this->DBMOD->getListProfStudentPerSubj($strSemLinkerID, $strUserID, $strProfSujID, $strSectionID, $strSearch, $strLimit, $strYear);
			
			return count($result);
			
		}
		
		public function getProfSubjectLabLecHours($strUserID, $strDeptID, $strYear) {
			
			#Prof and Subj
			$PSLLH = $this->DBMOD->getProfSubjectLabLecHours($strUserID); 
			
			if (!empty($PSLLH)) {
				foreach($PSLLH as $PSLLHValue) {
					
					$prof_subj	= $PSLLHValue['prof_subj_idPK'];
					$subj_id	= $PSLLHValue['subj_idFK'];
					$code		= $PSLLHValue['subj_code'];
					$lab 		= $PSLLHValue['lab_units'];
					$lec 		= $PSLLHValue['lec_units'];
					$lecLab 	= $PSLLHValue['lec_lab_units'];
					$totalUnits = abs($PSLLHValue['total_units']);
					$totalHrs	= $PSLLHValue['total_hrs'];
					$semLinker	= $PSLLHValue['sem_linker_idFK'];
					$saturday	= $PSLLHValue['is_saturday'];
					$sectionID	= $PSLLHValue['section_idPK'];
					$sectionDes	= $PSLLHValue['section_desc'];
					
					$lecHr 		= $lec; // 2
					$labHr 		= ( $totalHrs > $totalUnits ) ? ($totalHrs - $lec) : $lab; // 3
					$lecLabHr 	= $lecLab;
					if ( $saturday == 'N' ) {
						if ( $lecHr > 0 ) {
							for($lecHrI = 1; $lecHrI <= $lecHr; $lecHrI++) {
								$arrTimeTable[$semLinker][$sectionID]['weekdays'][$code]['lec'][][] = $prof_subj;
							}
						}
						if ( $labHr > 0 ) {
							for($labHrI = 1; $labHrI <= $labHr; $labHrI++) {
								$arrTimeTable[$semLinker][$sectionID]['weekdays'][$code]['lab']['hrs'][] = $prof_subj;
							}
						}
						if ( $lecLabHr > 0 ) {
							for($lecLabHrI = 1; $lecLabHrI <= $lecLabHr; $lecLabHrI++) {
								$arrTimeTable[$semLinker][$sectionID]['weekdays'][$code]['lec_lab']['hrs'][] = $prof_subj;
							}
						}
					}
					else {
						if ( $totalHrs > 0 ) {
							for($satI = 1; $satI <= $totalHrs; $satI++) {
								$arrTimeTable[$semLinker][$sectionID]['weekends'][$code]['lec']['hrs'][] = $prof_subj;
							}
						}
					}
				}
			}
			
			$this->DBMOD->deleteProfSubjSchedTemp($strUserID); // delete temporary sched
			
			if (!empty($arrTimeTable)) {
				foreach( $arrTimeTable as $schedSemLinkerField => $schedSemLinker ) {
					// $schedSemLinkerField - sem_linker_id
					foreach( $schedSemLinker as $sectionField => $schedSection ) {
						// $sectionField - section_idPK
						foreach( $schedSection as $weeksField => $schedWeeks ) {
							// $weeksField - Weekdays or Saturday
							foreach( $schedWeeks as $codeField => $schedCodes ) {
								// $codeField - IT101, CS101
								foreach( $schedCodes as $labLecField => $schedLecLab ) {
									//$labLecField - lec_lab | lec | lab
									
									if ( $labLecField == 'lab' || $labLecField == 'lec_lab' ) {
										$arrRooms 	=  $this->DBMOD->getRoomsForScheduling($strDeptID, '1');
										$lecLabBoth	= 1;
									}
									else {
										$arrRooms 	= $this->DBMOD->getRoomsForScheduling($strDeptID, '0');
										$lecLabBoth	= 0;
									} /* ------- $arrRooms['room_idPK'] ------- */
									
									foreach( $schedLecLab as $timeField => $timeValue ) {
										// $timeField - hrsx
										$timeValueCount = count($timeValue);
										
										do {
											$arrWeekTime = ( $weeksField == 'weekends' ) ? $this->DBMOD->getSchedSaturdayTime(): $this->DBMOD->getSchedDayTime(array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'), $strUserID, $arrRooms['room_idPK']);
											$countSchedLabLecSum = $timeValueCount + $arrWeekTime['sched_key'];
										}
										while ( $countSchedLabLecSum > 9 );
										
										if ( $weeksField == 'weekends' ) {
											$schedTimeLimitSave = $this->DBMOD->getSchedTimeLimitSaveSaturday($arrWeekTime['sched_int'], $arrWeekTime['sched_key'], $timeValueCount);
										}
										else {
											$schedTimeLimitSave = $this->DBMOD->getSchedTimeLimitSave($arrWeekTime['sched_int'], $arrWeekTime['sched_key'], $timeValueCount, $strUserID, $arrRooms['room_idPK']);
										}
										
										$schedTimeLimitSaveCounter  = 0;
										$strArray 		 = '';
										$duplicateReturn = 0;
										
										foreach( $timeValue as $profSubjField => $profSubjID ) {
											
											$strArray = array('prof_subj' 	=> $profSubjID,
															  'section'		=> $sectionField,
															  'room'		=> $arrRooms['room_idPK'],
															  'sched_time'	=> $schedTimeLimitSave[$schedTimeLimitSaveCounter]['sched_time_idPK'],
															  'lec_lab'		=> $lecLabBoth,
															  'year_id'		=> $strYear);
											
											$this->DBMOD->insertProfSubjSchedTemp($strArray);
											
											$schedTimeLimitSaveCounter++;
														  
										}
									}
								}
							}
						}
					}
				}
			}
		}
		
		public function insertProfSubjSchedTemp($strArray) {
			
			return $this->DBMOD->insertProfSubjSchedTemp($strArray);
		}
		
		public function getScheduleTimeID($strSchedTimeID) {
			
			return $this->DBMOD->getScheduleTimeID($strSchedTimeID);
		}
		
		public function getProfSubjList($strUserID, $strProfSubj = '') {
			
			return $this->DBMOD->getProfSubjList($strUserID, $strProfSubj);
		}
		
		public function getTotalUnitsProfSubj($strUserID) {
			
			$profSubjList = $this->getProfSubjList($strUserID);
			
			$profSubjView = 0;
			if (!empty($profSubjList)) {
				foreach($profSubjList as $profSubjListValue) {
					if ( $profSubjListValue['total_units'] > 0 ) {
						$profSubjView += abs($profSubjListValue['total_units']);
					}
				}
			}
			
			return $profSubjView;
			
		}
		
		public function getProfSectionList($strSchedTimeID = '', $strSemesterLinkerID = '') {
			
			return $this->DBMOD->getProfSectionList($strSchedTimeID, $strSemesterLinkerID);
		}
		
		public function getProfRoomList($strSchedTimeID = '') {
			
			return $this->DBMOD->getProfRoomList($strSchedTimeID);
		}
		
		public function getProfSubjActive($strProfSubj, $strSection = '') {
			
			return $this->DBMOD->getProfSubjActive($strProfSubj, $strSection);
			
		}
		
		public function getProfSubjectGenerateSchedules($strUserID, $strSchedTimeID) {
			
			return $this->DBMOD->getProfSubjectGenerateSchedules($strUserID, $strSchedTimeID);
			
		}
		
		public function getStudentActiveSubjectSchedules($strStudentID, $strSchedTimeID) {
			
			return $this->DBMOD->getStudentActiveSubjectSchedules($strStudentID, $strSchedTimeID);
			
		}
		
		public function getSectionSubjectGenerateSchedules($strSectionID, $strSchedTimeID, $activeYear) {
			
			return $this->DBMOD->getSectionSubjectGenerateSchedules($strSectionID, $strSchedTimeID, $activeYear);
			
		}
		
		public function getIrregularSubjectGenerateSchedules($strStudentID, $strCourseID, $strSemLinkerID, $strYearID, $strSchedTimeID, $strIsDeleted = false, $strSection = '') {
			
			return $this->DBMOD->getIrregularSubjectGenerateSchedules($strStudentID, $strCourseID, $strSemLinkerID, $strYearID, $strSchedTimeID, $strIsDeleted, $strSection);
		}
		
		public function getIrregularSubjectGenerateAutoSchedules($strSectionList, $strSubjectIDs, $strSchedTimeID) {
			
			return $this->DBMOD->getIrregularSubjectGenerateAutoSchedules($strSectionList, $strSubjectIDs, $strSchedTimeID);
		}
		
		public function getIrregularSubjectSchedulesiFrame($strStudentID, $strCourseID, $strSemLinkerID, $strYearID, $strSubjID) {
			
			$result 	= $this->DBMOD->getIrregularSubjectSchedulesiFrame($strStudentID, $strCourseID, $strSemLinkerID, $strYearID, $strSubjID);
			
			//$timeYear 	= $this->getTimeSchedule('sched_time', $strYearID, '', $return['sched_time_idPK']);
			$return = 0;
			if ( !empty($result) ) {
				foreach($result as $count) {
					$return += $count['sched_time'];
				}
			}
			return $return; //count($return) * round($return['sched_time'], 1);
		}
		
		public function saveSchedulesRemoveTemp($strUserID) {
			
			return $this->DBMOD->saveSchedulesRemoveTemp($strUserID);
			
		}
		
		public function getProfSubjectSchedulesIfHaveSched($strUserID) {
			
			$result = $this->DBMOD->getProfSubjectSchedulesIfHaveSched($strUserID);
			
			return $result['count'];
			
		}
		
		public function getListSectionProfStudenPerSubj($strSemLinkerID, $strUserID, $strProfSujID) {
			
			return $this->DBMOD->getListSectionProfStudenPerSubj($strSemLinkerID, $strUserID, $strProfSujID, $strSectionID);
			
		}
		
		public function getStudentRequestIrregularSubject($strID) {

			return $this->DBMOD->getStudentRequestIrregularSubject($strID);
			
		}
		
		public function getListProfStudentPerSubj($strSemLinkerID, $strUserID, $strProfSujID, $strSectionID = '', $strSearch = 'Search here...', $strLimit = '', $strYear = '') {
			
			if ( $strSearch == 'Search here...' ) $strSearch = '';
			
			return $this->DBMOD->getListProfStudentPerSubj($strSemLinkerID, $strUserID, $strProfSujID, $strSectionID, $strSearch, $strLimit, $strYear);
			
		}
		
		public function insertStudentRequest($strArray) {
			
			return $this->DBMOD->insertStudentRequest($strArray);
			
		}
		
		public function getStudentListRequestCount($strSearch = '') {
			
			$return = $this->getStudentListRequest($strSearch, '');
			return count($return);
			
		}
		
		public function getStudentListRequest($strSearch = 'Search here...', $strLimit = '') {
			
			if ( $strSearch == 'Search here...' ) $strSearch = '';
			
			return $this->DBMOD->getStudentListRequest($strSearch, $strLimit);
			
		}
		
		public function getStudentByhStudNo($strStudNo) {
			
			return $this->DBMOD->getStudentByhStudNo($strStudNo);
			
		}
		
		public function updateStudentRequestPassword($strArray, $strStudID) {
			
			return $this->DBMOD->updateStudentRequestPassword($strArray, $strStudID);
			
		}
		
		public function deleteStudentRequestPassword($strStudNo) {
			
			return $this->DBMOD->deleteStudentRequestPassword($strStudNo);
			
		}
		
		public function deleteTimeSchedule($strProfSubjSchedID) {
			
			$this->DBMOD->deleteTimeSchedule($strProfSubjSchedID);
			
		}
		
		
		public function getStudentSubjectAlreadyTaken($strStudentID, $strCourseID) {

			$return = $this->DBMOD->getStudentSubjectAlreadyTaken($strStudentID, $strCourseID);
			
			$result = '';
			if (!empty($return)) {
				foreach($return as $returnValue) {
					$result .= $returnValue['subj_idFK'] . '-';
				}
			}
			
			return $result;
			
		}
		
		public function insertStudentChangeSection($studID, $courseID, $semLinkerID, $yearID, $currentSectionID, $changeSectionID) {

			$returnID = $this->DBMOD->insertStudentChangeSection($studID, $courseID, $semLinkerID, $yearID, $currentSectionID, $changeSectionID);
			
			$studentInformation = $this->getStudentInformation($studID);
			$strArray		= array('stud_no'		=> $studentInformation['stud_no'],
									'first_name' 	=> $studentInformation['first_name'],
									'last_name' 	=> $studentInformation['last_name'],
									'middle_name' 	=> $studentInformation['middle_name'],
									'email' 		=> $studentInformation['email'],
									'message' 		=> $studentInformation['message'],
									'type' 			=> 'reg_section',
									'table_request' => 'tbl_stud_change_section',
									'table_id' 		=> $returnID);
			
			$this->DBMOD->insertStudentRequest($strArray);
			
		}
		
		public function getStudentChangeSectionActive($studID, $courseID, $semLinkerID, $yearID) {
			
			return $this->DBMOD->getStudentChangeSectionActive($studID, $courseID, $semLinkerID, $yearID);
			
		}
		
		public function IrregularSetScheduleStudent($strArray, $strAccepted = '', $strDeleted = 'N', $actionRequested = 1) {
			
			$getProfSubjActive = $this->DBMOD->getProfSubjActiveIrregular($strArray['ps_id'], $strArray['section_id'], $_POST['subj_id']);
			if ( !empty($getProfSubjActive) ) {
				foreach($getProfSubjActive as $getProfSubjActiveValue) {
					$strArray['prof_subj_sched_id'] = $getProfSubjActiveValue['prof_subj_sched_idPK'];
					$lastInsert = $this->DBMOD->IrregularSetScheduleStudent($strArray, $strArray, $strAccepted, $strDeleted);
				}
				
			}
		}
		
		public function IrregularDeleteScheduleStudent($strStudID, $strSCSIID, $strSubjLinker, $strSubjGroup, $actionRequested = 1) {
			
			//$this->DBMOD->IrregularDeleteScheduleStudent($strSCSIID);
			$this->DBMOD->IrregularDeleteScheduleStudent($strSubjLinker, $strSubjGroup);
			
		}
		
		public function RequestIrregularSchedule($strStudentNo, $strTableName) {
			$requestIrregularSchedule = $this->DBMOD->RequestIrregularSchedule($strStudentNo, $strTableName);
			return $requestIrregularSchedule['count'];
		}
		
		public function SendRequestIrregularSchedule($strStudID) {
			
			$sendRequestIrregularSchedule = $this->DBMOD->SendRequestIrregularSchedule($strStudID);
			
			if ( !empty($strStudID) && $sendRequestIrregularSchedule['count'] > 0 ) {
				$studentInformation = $this->getStudentInformation($strStudID);
				$strArray		= array('stud_no'		=> $studentInformation['stud_no'],
										'first_name' 	=> $studentInformation['first_name'],
										'last_name' 	=> $studentInformation['last_name'],
										'middle_name' 	=> $studentInformation['middle_name'],
										'email' 		=> $studentInformation['email'],
										'message' 		=> $studentInformation['message'],
										'type' 			=> 'irreg_schedule',
										'table_request' => 'tbl_stud_change_section_irreg');
				
				$this->DBMOD->insertStudentRequest($strArray);
			}
			
		}
		
		public function CancelRequestIrregularSchedule($strStudID) {
			
			$this->DBMOD->CancelRequestIrregularSchedule($strStudID);
			
		}
		
		public function getStudChangeSectionIrregSet($strStudentID, $strTimeID) {
			$return = $sendRequestIrregularSchedule = $this->DBMOD->getStudChangeSectionIrregSet($strStudentID, $strTimeID);
			return $return['count'];
		}
		
		public function SendRequestIrregularScheduleCount($strStudID) {
			
			$sendRequestIrregularSchedule = $this->DBMOD->SendRequestIrregularSchedule($strStudID);
			return $sendRequestIrregularSchedule['count'];
		}
		
		public function getIrregularRequestedSchedule($strStudentID, $strSemLinkerID) {
			
			$return = $this->DBMOD->getIrregularRequestedSchedule($strStudentID, $strSemLinkerID);
			
			if ( !empty($return) ) {
				foreach($return as $value) {
					$res[$value['is_deleted']][] = $value;
				}
			}
			
			return $res;
			
		}
		
		public function updateIrregularStudentSection($strStudentID, $strSemLinkerID, $strAction, $strStudentNo) {
			
			if ( $strAction == 'Y' ) {
				$this->DBMOD->requestIrregularStudentScheduleAccepted($strStudentID, $strSemLinkerID);
			}
			else {
				$this->DBMOD->requestIrregularStudentScheduleDenied($strStudentID, $strSemLinkerID);
			}
			
			$this->DBMOD->requestDeleteIrregularStudentSchedule($strStudentNo, 'tbl_stud_change_section_irreg');
			
		}
		
		
		public function SaveTimeSchedule($strAction, $strYear) {
			
			$days = array ( 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' );
				
			if ( $strAction == 0 ) {
				$data1 		= array ( '7:30', '8:00', '8:30', '9:00', '9:30', '10:00', '10:30', '11:00', '11:30', '12:00', '12:30', '1:00', '1:30', '2:00', '2:30', '3:00', '3:30', '4:00', '4:30', '5:00', '5:30', '6:00', '6:30', '7:00', '7:30', '8:00', '8:30' );
				$data2 		= array ( '8:00', '8:30', '9:00', '9:30', '10:00', '10:30', '11:00', '11:30', '12:00', '12:30', '1:00', '1:30', '2:00', '2:30', '3:00', '3:30', '4:00', '4:30', '5:00', '5:30', '6:00', '6:30', '7:00', '7:30', '8:00', '8:30', '9:00' );
				$countData 	= count($data1);
				$timeData 	= '0.5';
			}
			elseif ( $strAction == 1 ) {
				$data1 		= array ( '7:30', '8:30', '9:30', '10:30', '11:30', '12:30', '1:30', '2:30', '3:30', '4:30', '5:30', '6:30', '7:30', '8:30' );
				$data2 		= array ( '8:30', '9:30', '10:30', '11:30', '12:30', '1:30', '2:30', '3:30', '4:30', '5:30', '6:30', '7:30', '8:30', '9:30' );
				$countData 	= count($data1);
				$timeData 	= '1';
			}
			elseif ( $strAction == 2 ) {
				$data1 		= array ( '7:30', '9:00', '10:30', '12:00', '1:00', '2:30', '4:00', '5:30', '7:00' );
				$data2 		= array ( '9:00', '10:30', '12:00', '1:00', '2:30', '4:00', '5:30', '7:00', '8:30' );
				$countData 	= count($data1);
				$timeData 	= '1.5';
			}
			
			$intDay = 1;
			foreach($days as $daysValue) {
				for( $i = 0; $i < $countData; $i++ ) {
					$strArray = array('sched_int'	=> $intDay,
									  'sched_day'	=> $daysValue,
									  'sched_from'	=> $data1[$i],
									  'sched_to'	=> $data2[$i],
									  'sched_key'	=> $i + 1,
									  'sched_break'	=> 'N',
									  'sched_time'	=> $timeData,
									  'year_id'		=> $strYear);
									
					$this->DBMOD->SaveTimeSchedule($strArray);
				}
				$intDay++;  
			}
			
		}
		
		function insertTempTimeSchedule($strYear, $strSchedFrom, $strSchedTo, $strSchedKey, $strSchedTime) {
			
			$days = array ( 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' );
			$intDay = 1;
			$triggerID = md5(time());
			foreach($days as $daysValue) {
				$strArray = array('sched_int'	=> $intDay,
								  'sched_day'	=> $daysValue,
								  'sched_from'	=> $strSchedFrom,
								  'sched_to'	=> $strSchedTo,
								  'sched_key'	=> $strSchedKey,
								  'sched_break'	=> 'N',
								  'sched_time'	=> $strSchedTime,
								  'year_id'		=> $strYear,
								  'trigger_id'	=> $triggerID);
					
				$this->DBMOD->SaveTempTimeSchedule($strArray);
				$intDay++;  
			}
			return $triggerID;
		}
		
		function deleteTempSchedule($strTriggerID) {
			
			return $this->DBMOD->deleteTempSchedule($strTriggerID);
			
		}
		
		function saveTempScheduleToLive($strYearID) {
			
			$getTempAllSchedule = $this->DBMOD->getTempAllSchedule($strYearID);
			if ( !empty($getTempAllSchedule) ) {
				foreach($getTempAllSchedule as $getTempAllScheduleValue) {
					$tempAllSchedule[$getTempAllScheduleValue['sched_day']][] = $getTempAllScheduleValue;
				}
				
				foreach($tempAllSchedule as $tempAllScheduleValue) {
					
					foreach($tempAllScheduleValue as $tempAllScheduleValue) {
						$strArray = array('sched_int'	=> $tempAllScheduleValue['sched_int'],
										  'sched_day'	=> $tempAllScheduleValue['sched_day'],
										  'sched_from'	=> $tempAllScheduleValue['sched_from'],
										  'sched_to'	=> $tempAllScheduleValue['sched_to'],
										  'sched_key'	=> $tempAllScheduleValue['sched_key'],
										  'sched_break'	=> $tempAllScheduleValue['sched_break'],
										  'sched_time'	=> $tempAllScheduleValue['sched_time'],
										  'year_id'		=> $tempAllScheduleValue['year_idFK']);
						$this->DBMOD->SaveTimeSchedule($strArray);
					}
				}
				
				$this->DBMOD->truncateTempSchedule();
			}
			
		}
		
		function getTempLastSchedule($strYear) {
			
			return $this->DBMOD->getTempLastSchedule($strYear);
			
		}
		
		
		function getTempSchedule($strYear) {
			
			return $this->DBMOD->getTempSchedule($strYear);
			
		}
		
		public function getTimeSchedule($strField, $strYear, $strInt = '', $strID = '') {
			
			$return = $this->DBMOD->getTimeSchedule($strField, $strYear, $strInt, $strID);
			
			if ( !empty($return) ) {
				foreach($return as $value) {
					$arr[] = $value[$strField];
				}
			}
			
			return $arr;
			
		}
		
		public function getProfSubjSchedActive($strYear) {
			
			$return = $this->DBMOD->getProfSubjSchedActive($strYear);
			
			return $return['count'];
			
		}
		
		public function getIrregularAutoGenerateSchedulesCount($strStudentID, $strCourseID, $strSemLinkerID, $strYearID) {
			
			$return = $this->DBMOD->getIrregularAutoGenerateSchedulesCount($strStudentID, $strCourseID, $strSemLinkerID, $strYearID);
			
			return $return['count'];
		}
		
		public function changeTimeScheduleActive($strYear) {
			
			$this->DBMOD->changeTimeScheduleActive($strYear);
			
		}
		
		public function getStudentsIncGradeCount($strSearch) {
			
			$return = $this->getStudentsIncGrade($strSearch);
			
			return count($return);
		}
		
		public function getStudentsIncGrade($strSearch, $pageLimit = '') {
			
			return $this->DBMOD->getStudentsIncGrade($strSearch, $pageLimit);
			
		}
		
	}
?>